<template>
	<view v-show="i === index">
		<mescroll-uni :ref="'mescrollRef'+i" @init="mescrollInit" height="100%" :up="upOption" @up="upCallback"
			:down="downOption" @down="downCallback" :bottom="index == 0 ? 180 : index == 2 ? 260 : 90">
			<view class="data-list" v-for="(item, key) in listData" :key="key" @click="toInfo(item)">
				<view class="data-item">
					<view class="item-text item-line item-title">
						{{item.taskName}}
					</view>
					<view class="item-text item-line item-desc item-more">
						<view class="fixed-width">{{$t('baseCommon.time.startTime')}}</view>
						<view class="desc-val">{{item.planStartTime}}</view>
					</view>
					<view class="item-text item-line item-desc item-more">
						<view class="fixed-width">{{$t('baseCommon.time.endTime')}}</view>
						<view class="desc-val">{{item.planEndTime}}</view>
					</view>
					<view class="item-text item-line item-desc item-more">
						<view class="fixed-width">{{$t('baseCommon.status.state')}}</view>
						<view>
							<text class="red" v-if="index == 0">{{$t('inspection.taskPlan.toCheck')}}</text>
							<text class="orange" v-if="index == 1">{{$t('inspection.taskPlan.checking')}}</text>
							<text class="green" v-if="index == 2">{{$t('inspection.taskPlan.checked')}}</text>
						</view>
					</view>
				</view>
			</view>
		</mescroll-uni>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js"
	import MescrollMoreItemMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-more-item.js"
	import { taskPageList } from '@/api/business/inspect.js'

	export default {
		mixins: [
			MescrollMixin,
			MescrollMoreItemMixin
		],
		props: {
			i: Number,
			index: {
				type: Number,
				default () {
					return 0
				}
			},
			params: {
				type: Object,
				default () {
					return {}
				}
			}
		},
		data() {
			return {
				downOption: {
					auto: false
				},
				upOption: {
					auto: false
				},
				listData: [],
			}
		},
		methods: {
			downCallback() {
				this.mescroll.resetUpScroll();
			},
			upCallback(page) {
				let pager = {
					limit: page.size,
					pageNo: page.num
				}
				this.params.requestPage = pager
				if(this.params.planStartTime) {
					this.params.planStartTime = this.params.planStartTime  + ' 00:00:00'
				}
				// 任务状态:0-未发布 1-待检 2-检查中 3-完成 -1-取消
				this.params.taskState = this.index == 0 ? 1 : this.index == 1 ? 2 : 3
				this.params.isRecent = this.index == 0 && this.params.isRecent == 1 ? this.params.isRecent : ''

				uni.showLoading({
					title: this.$t('common.loading')
				})

				taskPageList(this.params).then(res => {
					uni.hideLoading()

					let curPageData = res.data.records
					let curPageLen = curPageData.length
					let totalSize = res.data.total
					if (page.num == 1) {
						//如果是第一页需手动置空列表
						this.listData = []
					}
					this.listData = this.listData.concat(curPageData) //追加新数据
					this.mescroll.endBySize(curPageLen, totalSize)
				})
			},
			toInfo(item) {
				this.$emit("toInfo", item)
			},
			reload() {
				if (this.i === this.index) {
					this.mescroll.resetUpScroll()
				}
			}
		}
	}
</script>

<style lang="scss">
	@import '@/static/style/common-list.scss';
	
	.data-list {
		padding: 0 12px;
		margin-top: 8px;
	}
	
	.item-line:last-of-type {
		border-bottom: 0;
	}
	
	.desc-val {
		color: #333;
	}
</style>
